﻿var xmlHttp = null;
/**
 * 检查帐号的输入有效性
 */
function checkUsername() {
	var elem = document.getElementById("username").value;
	var msg = document.getElementById("username-error");
	var usernameFormat = /^[_a-zA-Z0-9]{2,14}$/;
	if (elem.length == 0) {
		msg.innerHTML = "<span>&nbsp&nbsp用户名不能为空</span>";
		return false;
	} else if (!usernameFormat.test(elem)) {
		msg.innerHTML = "<span>&nbsp&nbsp用户名为2-14个英文字母、数字或下划线</span>";
		return false;
	} else {
		try {// Firefox, Opera 8.0+, Safari, IE7
			xmlHttp = new XMLHttpRequest();
		} catch (e) {// Old IE
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("您的浏览器不支持AJAX技术");
				return false;
			}
		}
		var url = "servlet/CheckNameServlet?username=" + elem;
		xmlHttp.open("GET", url, false);
		xmlHttp.send(null);
		if (xmlHttp.responseText == "true") {
			msg.innerHTML = "<span>&nbsp&nbsp用户名已经存在</span>";
			return false;
		}
	}
	msg.innerHTML = "<span class=\"green\">&nbsp&nbsp正确</span>";
	return true;
}
/**
 * 检查昵称的输入有效性
 */
function checkNickName() {
	var elem = document.getElementById("nick-name").value;
	var msg = document.getElementById("nick-name-error");
	if (elem.length == 0) {
		msg.innerHTML = "<span>&nbsp&nbsp昵称不能为空</span>";
	} else if (elem.length < 2 || elem.length > 14) {
		msg.innerHTML = "<span>&nbsp&nbsp昵称长度为2-14位</span>";
	} else {
		msg.innerHTML = "<span class=\"green\">&nbsp&nbsp正确</span>";
		return true;
	}
	;
}
/**
 * 检查密码的输入有效性
 */
function checkPass() {
	var elem = document.getElementById("pwd").value;
	var msg = document.getElementById("pwd-error");
	var pwdFormat = /^\d*[a-zA-Z!"#$%&'()*+,-.\/:;<=>?@[\]^_`{|}~]+\d*$/;
	if (elem.length == 0) {
		msg.innerHTML = "<span>&nbsp&nbsp密码不能为空</span>";
	} else if (elem.length < 6) {
		msg.innerHTML = "<span>&nbsp&nbsp密码长度不能小于6位</span>";
	} else if (!pwdFormat.test(elem)) {
		msg.innerHTML = "<span>&nbsp&nbsp密码为英文字母、数字或符号，且不为纯数字</span>";
	} else {
		checkPass1();
		return true;
	}
	;
	return false;
}
/**
 * 实时检查检查密码强度
 */
function checkPass1() {
	var elem = document.getElementById("pwd").value;
	var msg = document.getElementById("pwd-error");
	var STR1 = "<span class=\"green\">&nbsp&nbsp密码强度：";
	var STR2 = "</span>";
	var str3;
	if (elem.length >= 4 && elem.length <= 7) {
		str3 = "<strong class=\"orange\">弱</strong>";
	} else if (elem.length >= 8 && elem.length <= 12) {
		str3 = "<strong class=\"yellow\">中</strong>";
	} else {
		str3 = "<strong class=\"green\">强</strong>";
	}
	msg.innerHTML = STR1 + str3 + STR2;
}
/**
 * 检查确认密码
 */
function checkConfirm() {
	var elem = document.getElementById("re-pwd").value;
	var msg = document.getElementById("re-pwd-error");
	if (elem.length == 0) {
		msg.innerHTML = "<span>&nbsp&nbsp确定密码不能为空</span>";
	} else if (elem != document.getElementById("pwd").value) {
		msg.innerHTML = "<span>&nbsp&nbsp两次密码不一致</span>";
	} else {
		msg.innerHTML = "<span class=\"green\">&nbsp&nbsp正确</span>";
		return true;
	}
	;
}
/**
 * 检查来处
 */
function checkFrom() {
	var elem = document.getElementById("come-from").value;
	var msg = document.getElementById("come-from-error");
	if (elem.length == 0) {
		msg.innerHTML = "<span>&nbsp&nbsp来自不能为空</span>";
	} else if (elem.length < 2 || elem.length > 14) {
		msg.innerHTML = "<span>&nbsp&nbsp来自长度为2-14位</span>";
	} else {
		msg.innerHTML = "<span class=\"green\">&nbsp&nbsp正确</span>";
		return true;
	}
}
/**
 * 检查所有文本输入框的有效性
 */
function checkAll() {
	if (checkUsername() & checkNickName() & checkPass() & checkConfirm()
			& checkFrom()) {
		if(getLat()!=null && getLng()!=null){
					return true;
		}else{
			return false;
		}

	}
	return false;
}

function getLat(){
				var lat;
				var Xelem = document.getElementById("x-Coordinate");
				if(google.loader.ClientLocation){
					lat = google.loader.ClientLocation.latitude;
				}else{
					lat = 31.191434;
				}
				Xelem.value=lat;
				return lat;
			}
			
			function getLng(){
				var lng;
				var Yelem = document.getElementById("y-Coordinate");
				if(google.loader.ClientLocation){
      				lng = google.loader.ClientLocation.longitude;
				}else{
					lng= 121.599437;
				}
				Yelem.value=lng;
				return lng;
			
			}